//TODO: Make styles std::stings

#include "WindowBox.hpp"

#include <Wt/WApplication>


//NOTE The order "addWidget()" is called mattters, just like on a web page.
webpages::windowboxes::WindowBox::WindowBox(Wt::WContainerWidget* parent)
    :
        Wt::WContainerWidget(parent),
        m_title("WindowBox: default name")
{
    setStyleClass("windowbox");
    
    
    addWidget(&m_title);
    m_title.setStyleClass("titlestyle");

    
    m_theme_selector = new Wt::WContainerWidget;
    m_theme_selector->setStyleClass("themeselector");
    addWidget(m_theme_selector);
        
    
    m_display_area.setStyleClass("displayarea");
    addWidget(&m_display_area);
    
    
//     Wt::WApplication::instance()->styleSheet().addRule(".windowbox",
//                                                        "background: red;"
//                                                        "position: absolute;"
//                                                        "border-color: silver;"
//                                                        "border-width: thick;"
//                                                        "border-style: ridge;"
//                                                        //     "float: right"
//                                                        "right: 10px;"
//                                                        "top: 10px;"
//                                                        "width: 300px;"
//                                                        "height: 100px;");
    
    
    
    
    
    
    
    
    
    
    setCSS3Styling();   
    

}


#include "TitleStyle.hpp"
#include "Geometry.hpp"
#include "Theme.hpp"
#include <string>

void webpages::windowboxes::WindowBox::setCSS3Styling()
{
    Wt::WApplication::instance()->styleSheet().addRule(new webpages::windowboxes::TitleStyle);
//     Wt::WApplication::instance()->styleSheet().addRule(new webpages::windowboxes::Geometry);
    Wt::WApplication::instance()->styleSheet().addRule(new webpages::windowboxes::Theme);
    

   
    //BEGIN: Testing the colors that can be changed by a theme. This is how theme selection ...
    std::string theme_style(
        "height:10pt;"
        "width:10pt;"
        "float:right;"
        "border-radius:50%;"
        "border-style:solid;"
        "border-width: thin;"
        "border-color:gray;"
        "margin-top: 3pt;"
        "margin-right: 6px;"
        //Shadow box didn't look great on small buttons.
        //"box-shadow: 0 0 3pt 0px rgba(0, 0, 255, .3);"
    );
    
    std::string theme_style_color;
    
    int n = 1; //obviously for testing.
    
    if (n == 0) //blue
    {
        theme_style_color = "background: rgba(0, 0, 255, 1);"
        "background-image:"
        "radial-gradient(circle closest-side at center, rgba(0, 0, 255, 0) 60%, rgba(255, 255, 255, .5) 100%),"
        "radial-gradient(circle closest-corner at center 8%,  rgba(255,255,255, .8) 0%, rgba(0, 0, 255, 0) 100%);";
    }
    
    if (n == 1) //black
    {
        theme_style_color = "background: rgba(0, 0, 0, 1);"
        "background-image:"
        "radial-gradient(circle closest-side at center, rgba(0, 0, 0, 0) 60%, rgba(255, 255, 255, .5) 100%),"
        "radial-gradient(circle closest-corner at center 8%,  rgba(255,255,255, .8) 0%, rgba(0, 0, 0, 0) 100%);";
    }
    
    if (n == 2) //red
    {
        theme_style_color = "background: rgba(255, 0, 0, 1);"
        "background-image:"
        "radial-gradient(circle closest-side at center, rgba(255, 0, 0, 0) 60%, rgba(255, 255, 255, .5) 100%),"
        "radial-gradient(circle closest-corner at center 8%,  rgba(255,255,255, .8) 0%, rgba(255, 0, 0, 0) 100%);";
    }
    
    theme_style += theme_style_color;
    
    /* A button to set the theme. Really, a placeholder for something more important. */
    Wt::WApplication::instance()->styleSheet().addRule(".themeselector", theme_style);
    
    //END: Testing the colors that can be changed by a theme. This is how theme selection ...
    
    /*
     * Sets the look of the button when it's clicked.
     */
    Wt::WApplication::instance()->styleSheet().addRule(".themeselector:active",
        "border-style: normal;"
        "border-width: thin;"
        "border-color: white;"
        
        "box-shadow: 0 0 3pt 0px rgba(255,255,255, .3);"
        
//         "box-shadow:0px 0px 5px white;"
//         /* move the "light" glow */
//         "background-image:   radial-gradient(circle closest-corner at center 2pt,  rgba(0,0,0,.3) 0%, #000000 85%),"
//         "radial-gradient(circle closest-side at center, #FFFFFF 83%, #000000 7%);"
                                                       
        "background-image:"
            "radial-gradient(circle closest-side at center, rgba(0, 0, 0, 0) 60%, rgba(255, 255, 255, .5) 100%),"
            "radial-gradient(circle closest-corner at center 25%,  rgba(255,255,255, .8) 0%, rgba(0, 0, 0, 0) 100%);"
    );
    
    
    //This needs to be part of the theme above:
    Wt::WApplication::instance()->styleSheet().addRule(".displayarea",
                                                       "clear: both;"
                                                       "border-top-color: silver;"
                                                       "border-top-width: 2px;"
                                                       "border-top-style: ridge;"
                                                       "background: rgba(0, 0, 0, 1);"
                                                       "height: 100%;");
}
